package teehee.Action;

/**
 * General class that contains methods to convert a String to and from a format that can be read by the database.
 * 
 * @author Alec
 *
 */

public class Action
{
	/**
	 * Converts a String to a format that can be used by the database. E.g. "The QuIck BroWn FoX" -> "the_quick_brown_fox"
	 * </br>Pre-conditions:</br>
	 * <ul>Must contain only [A-Za-z], [0-9].</ul>
	 * <ul>String must not begin or end with space characters</ul>
	 * <ul>String must not contain double spaces</ul>
	 * 
	 * @param s The String to convert
	 * 
	 * @return The String, converted to database format.
	 */
	
   public static String convertToDbFormat(String s)
   {
      return s.replace(" ", "_").toLowerCase();
   }
   
	/**
	 * Converts a String from a format that can be used by the database. to human readable format. E.g. "the_quick_brown_fox" -> "The Quick Brown Fox"
	 * </br>Pre-conditions: String must be in format that can be used by our database.
	 * 
	 * @param s The String to convert
	 * 
	 * @return The String, in human-readable form.
	 */
   
   public static String convertBack(String s)
   {
	  if(s.length() < 2)
	     return s.toUpperCase().replace("_", " ");
	   
	   String f = "";
	   for(String x : s.split("_"))
		 f += x.substring(0, 1).toUpperCase() + x.substring(1) + " ";
       
     //shoddy logic
	   return f.trim();
   }
}
